cd  "E:\Replication Data for Media Freedom and Public Trust in Science" 

use Data_Gu_WVS, clear

global cov i.female i.emp  i.income2 i.E033 c.age 
global cov2 female emp income2 E033 age edulevel2

**#Table 1: Multi-level Analysis of Science Attitudes from the WVS
eststo clear

eststo m1: mixed y2_wvs || country:, mle
estat icc
estadd scalar ICC = r(icc2)*100 

eststo m2: mixed y2_wvs $cov2 || country:, mle
estat icc
estadd scalar ICC = r(icc2)*100 

local var Mexp_conVDem_14after
eststo m3: mixed y2_wvs $cov2 `var' || country:, mle
estat icc
estadd scalar ICC = r(icc2)*100 
qui tab country if `var' != .
estadd scalar N2 = r(r)
eststo m4: mixed y2_wvs $cov2 c.`var'##c.edulevel2 || country:, mle
estat icc
estadd scalar ICC = r(icc2)*100 
qui tab country if `var' != .
estadd scalar N2 = r(r)

local var Mexp_binVDem_14after
eststo m5: mixed y2_wvs $cov2 `var' || country:, mle
estat icc
estadd scalar ICC = r(icc2)*100 
qui tab country if `var' != .
estadd scalar N2 = r(r)
eststo m6: mixed y2_wvs $cov2 c.`var'##c.edulevel2 || country:, mle
estat icc
estadd scalar ICC = r(icc2)*100 
qui tab country if `var' != .
estadd scalar N2 = r(r)

esttab m* using TW1.rtf , b(3) se(3) nonote nobaselevel noomitted eqlabel(none) label  replace  star(+ 0.1 * 0.05 ** 0.01 *** 0.001)  nomtitles /// 
keep( _cons female emp income2 E033 age edulevel2 Mexp_conVDem_14after Mexp_binVDem_14after c.Mexp_conVDem_14after#c.edulevel2 c.Mexp_binVDem_14after#c.edulevel2)  ///
order(_cons) ///
varlabel( _cons "Constant" female "Female" emp "Employment status" income2 "Income" edulevel2 "Education level" E033 "Self positioning in political scale" Mexp_conVDem_14after "Continuous media freedom exposure" c.Mexp_conVDem_14after#c.edulevel2 "Continuous media freedom exposure × Education level" Mexp_binVDem_14after "Binary media freedom exposure" c.Mexp_binVDem_14after#c.edulevel2 "Binary media freedom exposure × Education level" ) ///
mgroup("{\i DV = Trust in Science (PCA, from the WVS)}") ///
stats( ICC N2 N, labels( "ICC (%)" "Country-Level Observations" "Individual-Level Observations") fmt( 2 0 0 ))  ///
title({\b Multilevel Model from the WVS: Media Freedom Exposure and Education Level})  ///
note("{\i \b Notes:} + {\i p} < 0.1, * {\i p} < 0.05, ** {\i p} < 0.01,*** {\i p} < 0.001 (two-tailed test).")

**#Table 2: Fixed Effects Model from the WVS: Media Freedom Exposure and Education Level 
eststo clear

local dv y2_wvs
local var Mexp_conVDem_14after
reghdfe `dv' ///
c.`var'##i.edulevel2  , a(i.S003##i.wave) cluster(country_cohort) keepsing
local r2=e(r2_a)
eststo m1: expint `dv' `var' beta
estadd scalar r2a=`r2'
estadd local rfe "√" 

local dv y2_wvs
local var Mexp_conVDem_14after
reghdfe `dv' ///
c.`var'##i.edulevel2  , a(i.S003##i.wave i.birthyear) cluster(country_cohort) keepsing
local r2=e(r2_a)
eststo m2: expint `dv' `var' beta
estadd scalar r2a=`r2'
estadd local rfe "√" 
estadd local bfe "√" 

local dv y2_wvs
local var Mexp_conVDem_14after
reghdfe `dv' ///
c.`var'##i.edulevel2  $cov##c.`var' , a(i.S003##i.wave i.birthyear) cluster(country_cohort) keepsing
local r2=e(r2_a)
eststo m3: expint `dv' `var' beta
estadd scalar r2a=`r2'
estadd local rfe "√" 
estadd local bfe "√" 
estadd local ctrl "√" 

local dv y2_wvs
local var Mexp_binVDem_14after
reghdfe `dv' ///
c.`var'##i.edulevel2  $cov##c.`var' , a(i.S003##i.wave i.birthyear) cluster(country_cohort) keepsing
local r2=e(r2_a)
eststo m4: expint `dv' `var' beta
estadd scalar r2a=`r2'
estadd local rfe "√" 
estadd local bfe "√" 
estadd local ctrl "√" 

esttab m* using TW2.rtf , b(3) se(3) nonote nobaselevel  unstack noomitted  eqlabel(none) label  replace  star(+ 0.1 * 0.05 ** 0.01 *** 0.01) refcat(primary "{\i Effect of cumulative exposure to media freedom on}" , nolabel) /// 
varlabel(primary "Primary education or below" secondary "Secondary education" tertiary "College education or above") ///
mgroup("{\i DV = Trust in Science (PCA, from the WVS)}", pattern(1 0 0 0 0 0) ) ///
mtitles("{\i Continuous Media Freedom Exposure (V-Dem)}" "{\i Continuous Media Freedom Exposure (V-Dem)}" "{\i Continuous Media Freedom Exposure (V-Dem)}" "{\i Binary Media Freedom Exposure (V-Dem)}" "{\i Continuous Media Freedom Exposure (V-Dem)}" "{\i Binary Media Freedom Exposure (V-Dem)}") ///
stats(rfe bfe ctrl r2a N, labels("Country-survey wave FE" "Birth year FE" "Individual-level controls × Media freedom" "Adjusted R²"  "Observations") fmt( 0 0 0 3 0 ) ) ///
title({\b Fixed Effects Model from the WVS: Media Freedom Exposure and Education Level }) ///
note("{\i \b Notes:} + {\i p} < 0.1, * {\i p} < 0.05, ** {\i p} < 0.01,*** {\i p} < 0.001 (two-tailed test).")
